package csd.wyaiyr.com.config;




import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;



@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    //处理自定义异常
    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public BaseResult handleBusinessException(BusinessException e) {
        log.error("BusinessException异常：{}",e.getMessage(),e);
        return BaseResult.error(500,e.getMessage());
    }

    //处理自定义异常
    @ExceptionHandler(SysException.class)
    @ResponseBody
    public BaseResult handleSysException(SysException e) {
        throw new SysException(e.getMessage());
    }

    //处理系统异常
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public BaseResult handleException(Exception e) {
        log.info("系统异常：",e);
        return BaseResult.error(500, e.getMessage());
    }

 

}
